package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.domain.CraftOperationDevice;
import com.uwlaser.service.CraftOperationDeviceService;
import com.uwlaser.service.dto.CraftOperationDeviceDto;
import com.uwlaser.service.dto.CraftOperationDeviceQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author zk-Qin
* @date 2022-05-18
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "工序设备关系表管理")
@RequestMapping("/api/craftOperationDevice")
public class CraftOperationDeviceController {

    private final CraftOperationDeviceService craftOperationDeviceService;

    @GetMapping
    @Log("查询工序设备关系表-分页")
    @ApiOperation("查询工序设备关系表-分页")
    @PreAuthorize("@el.check('craftOperationDevice:list')")
    public ResponseEntity query(CraftOperationDeviceQueryParam query, Pageable pageable){
        return new ResponseEntity<>(craftOperationDeviceService.queryAll(query,pageable),HttpStatus.OK);
    }

    @GetMapping("/list")
    @Log("查询工序设备关系表-列表")
    @ApiOperation("查询工序设备关系表-列表")
    @PreAuthorize("@el.check('craftOperationDevice:list','craftOperation:list')")
    public ResponseEntity list(CraftOperationDeviceQueryParam query){
        return new ResponseEntity<>(craftOperationDeviceService.queryAll(query),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增工序设备关系表")
    @ApiOperation("新增工序设备关系表")
    @PreAuthorize("@el.check('craftOperationDevice:add')")
    public ResponseEntity create(@Validated @RequestBody CraftOperationDeviceDto resources){
        return new ResponseEntity<>(craftOperationDeviceService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改工序设备关系表")
    @ApiOperation("修改工序设备关系表")
    @PreAuthorize("@el.check('craftOperationDevice:edit')")
    public ResponseEntity update(@Validated @RequestBody CraftOperationDeviceDto resources){
        craftOperationDeviceService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除工序设备关系表")
    @ApiOperation("删除工序设备关系表")
    @PreAuthorize("@el.check('craftOperationDevice:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        craftOperationDeviceService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出工序设备关系表")
    @ApiOperation("导出工序设备关系表")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('craftOperationDevice:list')")
    public void download(HttpServletResponse response, CraftOperationDeviceQueryParam query) throws IOException {
        craftOperationDeviceService.download(craftOperationDeviceService.queryAll(query), response);
    }*/

}
